///////////G2G/////////////
///Avaya CSV DATA Format///
///////////G2G/////////////
var rs=datai.recordset;
var statArray=new Array();
/*************************************************************************************************************************************************************************************
Below is the key to format array settings unless you are
comfortable with Javascript.
Key: ['Table header or footer', Data field position or derived array
position,  Time Value true or false, Yellow Standard, Red Standard,
Derived Value True or False]
**************************************************************************************************************************************************************************************/
statArray=[
['Interval',0,false,,,false],
['Calls',3,false,220,180,false],
['Avg Talk Time',4,true,516,591,false],
['Avg AfterCall',5,true,9,12,false],
['Staff Time',18,true,,,false],
['Calls Held',20,false,55,80,false],
['Percent of Calls on Hold',5,false,25,35,true,13],
['Avg Hold per Held Call',21,true,120,150,false],
['Avg Hold per Call',3,true,20,30,true],
['Avg Hold per Hour',4,true,165,205,true,12],
['Aftercall',13,true,3000,4500,false],
['Productivity',0,false,80,70,true],
['Average Handle Time',1,true,525,600,true],
['Calls Per Hour',2,false,5.5,4.8,true]
];
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//please do not edit below////please do not edit below////please do not edit below////please do not edit below////please do not edit below////please do not edit below////please do not edit below//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function pad(num){return((num>9)?num:"0"+num);}
function cvert(val){var tnseconds=(Math.round(val));var tnminutes=Math.floor(tnseconds/60);tnseconds -= tnminutes*60;var tnhours=Math.floor(tnminutes/60);tnminutes-=tnhours*60;var convertValue=pad(tnhours)+":"+pad(tnminutes)+":"+pad(tnseconds);return convertValue;}
//write table
document.close;
rs.movefirst();
var ifs="";
ifs+="<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>";
ifs+="<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">";
ifs+="<html xmlns=\"http://www.w3.org/1999/xhtml\">";
ifs+="<head>";
ifs+="<title>"+document.title+"</title>";
ifs+="<link rel=\"stylesheet\" title=\"RealTimeStatsCSS\" media=\"screen\" href=\""+document.getElementsByTagName('link').item(0).href+"\" />";
ifs+="<script type='text/javascript'>function pagerefresh(){window.history.go(-1);} setTimeout('pagerefresh()',600000)</script>"
ifs+="</head>";
ifs+="<body>";
ifs+="<div id='stat'>";
ifs+="<a href=\"javascript:window.history.go(-1)\">Refresh</a>";
ifs+="<p>"+((document.title).substring(((document.title).indexOf("-")+1),((document.title).length)))+"</p>";
ifs+="<table class='repTable'>";
//table header
ifs+="<thead><tr>";
for(var z=0;z<statArray.length;z++){
	ifs+="<th>"+statArray[z][0]+"</th>";
}
ifs+="</tr></thead><tbody>";
//end table header
//table contents
for(var j=0;j<rs.recordcount;j++){
	/************************************************************
	It was necessary to place the formulas for derived variables
	within the table contents loop in order for the table to be
	rendered properly
	************************************************************/
	var derivedArray=new Array()
	derivedArray=[
		[productivity=Math.round(100*(((parseFloat(rs.fields(12)))+(parseFloat(rs.fields(17))))/(parseFloat(rs.fields(18))))) + "%"],
		[AHT=(parseFloat(rs.fields(4)) + parseFloat(rs.fields(5)))],
		[CPH=(parseFloat(rs.fields(3))/(parseFloat(rs.fields(18))/(60*60))).toString().substring(0,4)],
		[HOLD=(parseFloat(rs.fields(3))!=0)?((parseFloat(rs.fields(21)))*(parseFloat(rs.fields(20))))/(parseFloat(rs.fields(3))):0],
	[HPH=(parseFloat(rs.fields(3))!=0)?((parseFloat(rs.fields(21)))*(parseFloat(rs.fields(20))))/((parseFloat(rs.fields(18)))/(60*60)):0],
	[PCH=Math.round(((parseFloat(rs.fields(20)))/(parseFloat(rs.fields(3))))*100)+"%"]
	];
	/****************************
	End Derived Variables Array
	*****************************/
	if(j==0){
		ifs+="<tr class='total'>";
	}
	else if(j%2==1){
		ifs+="<tr class='even'>";
	}
	else{
		ifs+="<tr>";
	}
	for(var i=0;i<statArray.length;i++){
		var isTime=statArray[i][2];
		var standard=statArray[i][3];
		var urgent=statArray[i][4]
		var isDerived=statArray[i][5];
		var minStandard=(standard>urgent)?true:false;
		if (minStandard){
			if(((!(isDerived)) && ((rs.fields(statArray[i][1]))<standard) && ((rs.fields(statArray[i][1]))>=urgent))||((isDerived) && (parseFloat(derivedArray[statArray[i][1]])<standard) && (parseFloat(derivedArray[statArray[i][1]])>=urgent))){
				if(isTime){
					ifs+=(isDerived)?"<td class='notgoodenough col"+i+"' title='"+derivedArray[statArray[i][1]]+"'>"+cvert(derivedArray[statArray[i][1]])+"</td>":"<td class='notgoodenough col"+i+"' title='"+rs.fields(statArray[i][1])+"'>"+cvert(rs.fields(statArray[i][1]))+"</td>";
				}
				else {
					ifs+=(isDerived)?"<td class='notgoodenough col"+i+"'>"+(derivedArray[statArray[i][1]])+"</td>":"<td class='notgoodenough col"+i+"'>"+(rs.fields(statArray[i][1]))+"</td>";
				}
			}
			else if(((!(isDerived)) && ((rs.fields(statArray[i][1]))<urgent))||((isDerived) && (parseFloat(derivedArray[statArray[i][1]])<urgent))){
				if(isTime){
					ifs+=(isDerived)?"<td class='whoa col"+i+"' title='"+derivedArray[statArray[i][1]]+"'>"+cvert(derivedArray[statArray[i][1]])+"</td>":"<td class='whoa col"+i+"' title='"+rs.fields(statArray[i][1])+"'>"+cvert(rs.fields(statArray[i][1]))+"</td>";
				}
				else {
					ifs+=(isDerived)?"<td class='whoa col"+i+"'>"+(derivedArray[statArray[i][1]])+"</td>":"<td class='whoa col"+i+"'>"+(rs.fields(statArray[i][1]))+"</td>";
				}
			}
			else {
				if(isTime){
					ifs+=(isDerived)?"<td class='col"+i+"' title='"+derivedArray[statArray[i][1]]+"'>"+cvert(derivedArray[statArray[i][1]])+"</td>":"<td class='col"+i+"' title='"+rs.fields(statArray[i][1])+"'>"+cvert(rs.fields(statArray[i][1]))+"</td>";
				}
				else {
					ifs+=(isDerived)?"<td class='col"+i+"'>"+(derivedArray[statArray[i][1]])+"</td>":"<td class='col"+i+"'>"+(rs.fields(statArray[i][1]))+"</td>";
				}
			}
		}
		else {
			if(((!(isDerived)) && ((rs.fields(statArray[i][1]))>standard) && ((rs.fields(statArray[i][1]))<=urgent))||((isDerived) && (parseFloat(derivedArray[statArray[i][1]])>standard) && (parseFloat(derivedArray[statArray[i][1]])<=urgent))){
				if(isTime){
					ifs+=(isDerived)?"<td class='notgoodenough col"+i+"' title='"+derivedArray[statArray[i][1]]+"'>"+cvert(derivedArray[statArray[i][1]])+"</td>":"<td class='notgoodenough col"+i+"' title='"+rs.fields(statArray[i][1])+"'>"+cvert(rs.fields(statArray[i][1]))+"</td>";
				}
				else {
					ifs+=(isDerived)?"<td class='notgoodenough col"+i+"'>"+(derivedArray[statArray[i][1]])+"</td>":"<td class='notgoodenough col"+i+"'>"+(rs.fields(statArray[i][1]))+"</td>";
				}
			}
			else if(((!(isDerived)) && ((rs.fields(statArray[i][1]))>urgent))||((isDerived) && (parseFloat(derivedArray[statArray[i][1]])>urgent))){
				if(isTime){
					ifs+=(isDerived)?"<td class='whoa col"+i+"' title='"+derivedArray[statArray[i][1]]+"'>"+cvert(derivedArray[statArray[i][1]])+"</td>":"<td class='whoa col"+i+"' title='"+rs.fields(statArray[i][1])+"'>"+cvert(rs.fields(statArray[i][1]))+"</td>";
				}
				else {
					ifs+=(isDerived)?"<td class='whoa col"+i+"'>"+(derivedArray[statArray[i][1]])+"</td>":"<td class='whoa col"+i+"'>"+(rs.fields(statArray[i][1]))+"</td>";
				}
			}
			else {
				if(isTime){
					ifs+=(isDerived)?"<td class='col"+i+"' title='"+derivedArray[statArray[i][1]]+"'>"+cvert(derivedArray[statArray[i][1]])+"</td>":"<td class='col"+i+"' title='"+rs.fields(statArray[i][1])+"'>"+cvert(rs.fields(statArray[i][1]))+"</td>";
				}
				else {
					ifs+=(isDerived)?"<td class='col"+i+"'>"+(derivedArray[statArray[i][1]])+"</td>":"<td class='col"+i+"'>"+(rs.fields(statArray[i][1]))+"</td>";
				}
			}
		}
	}
	ifs+="</tr>";
	rs.movenext();
};

//end table contents
//table footer
ifs+="</tbody><tfoot><tr class='sortbottom'>";
for(var y=0;y<statArray.length;y++){
	var foun=(statArray[y][5])?statArray[y][0]+"&#10;Derived Calculation "+statArray[y][1]:statArray[y][0]+"&#10;RecordSet field "+statArray[y][1];
	ifs+="<th title='"+foun+"'>"+statArray[y][0]+"</th>";
}
ifs+="</tr></tfoot>";
//end table footer
ifs+="</table>";
//Begin Graph
function getHigh(){rs.movefirst();rs.movenext();var highval=0;for(var v=1;v<rs.recordcount;v++){var CPH=parseFloat((rs.fields(3))/(parseFloat(rs.fields(18))/(60*60)));highval=(CPH > highval)?CPH:highval;rs.movenext();}var topyvalue=Math.ceil(highval);return topyvalue}
topyvalue=getHigh();
var yinterval=2800/topyvalue;ifs+="<div id=\"g1\">";
ifs+="<v:group style='width:400pt;height:300pt' coordsize=\"4000,3000\">";
/* Paper is white with a simple drop-shadow */
ifs+="<v:rect style='width:4000;height:3000' fillcolor=\"#ffffff\">";
ifs+="<v:shadow on=\"true\" offset=\"4pt,3pt\" color=\"#cccccc\" />";
ifs+="</v:rect>";
/*Inside Border*/
ifs+="<v:roundrect style='position:absolute;left:40;top:40;width:3920;height:2940;' fillcolor=\"#FFFFFF\" strokeweight=\"1px\" />";
/*Grid*/
/*X-axis and Y-axis Zero Gridlines 80% of 4000 and 3000*/
ifs+="<v:group style='position:absolute;top:7%;left:15%;width:80%;height:80%;' coordsize=\"4000,3000\">";
ifs+="<v:shape style='position:absolute;top:0;left:0;width:100%;height:100%;' strokecolor=\"#999999\" strokeweight=\"1pt\" >";
ifs+="<v:stroke joinstyle=\"round\" endcap=\"round\" />";
ifs+="<v:fill on=\"false\" />";
ifs+="<v:path v=\"m 100,100 l 100,2900 4000,2900 3900,3000 0,3000 0,200 m 0,200 l 100,100 4000,100 4000,2900 m 0,3000 l 100,2900 ";
for(var t=1;t<topyvalue;t++){

ifs+="    m 0,"+(200+parseInt(t*yinterval))+" l 100,"+(100+parseInt(t*yinterval))+" 4000,"+(100+parseInt(t*yinterval));

}
ifs+="e\"/>";
for(var u=0;u<topyvalue;u++){
var yspacing=100/topyvalue;

ifs+="<p class=\"yChart\" style='position:absolute;left:-2em;top:"+(yspacing*u)+"%;'>"+(topyvalue-u)+".00</p>";

}
ifs+="</v:shape>";
/*Bar Graphs 2800/8=350=1 CPH        3.50=0.01 CPH 17.5% */
rs.movefirst();
rs.movenext();
for(var w=1;w<rs.recordcount;w++){
var CPH=parseFloat((rs.fields(3))/(parseFloat(rs.fields(18))/(60*60)));
var aCPH=CPH.toString().substring(0,4);
var barinterval=100/(rs.recordcount+1);
var barpos=barinterval*w+"%";
var aw=(rs.fields(0)).value.toString();
var weekstart=aw;/*.substring(0,(aw.lastIndexOf("/")));*/

ifs+="<v:rect title='"+aCPH+"'style='position:absolute;left:"+barpos+";top:"+(3000-(CPH*yinterval))+";width:4%;height:"+(CPH*yinterval)+";' fillcolor=\"#daddef\" strokeweight=\"0.4\"><v:extrusion metal='t' colormode=\"custom\" color=\"#7777ff\" backdepth=\"22.5pt\" on=\"True\"/></v:rect>";
ifs+="<v:shape style='position:absolute;top:200;left:"+barpos+";width:100%; height:100%' path=\"M 0,3000 L 100,2900\" fillcolor=\"#000000\" strokeweight=\"0px\" >";
ifs+="<v:stroke on='f' />";
ifs+="<v:path textpathok=\"t\" />";
ifs+="<v:textpath on=\"1\" style='font:12pt Arial;' string='"+weekstart+"' />";
ifs+="</v:shape>";
rs.movenext();
}
ifs+="</v:group>";
/*Graph Title*/
ifs+="<v:shape style='position:absolute; width:4000; height:3000' path=\"M 0,200 L 4000,200\" fillcolor=\"#000000\" >";
ifs+="<v:stroke on=\"0\" />";
ifs+="<v:path textpathok=\"t\" />";
ifs+="<v:textpath on=\"1\" style='font:24pt bold Arial ;' string=\"CPH\" />";
ifs+="</v:shape>";
/*Y-axis Title*/
ifs+="<v:shape style='position:absolute; width:4000; height:3000' path=\"M 180,3000 L 180,0\" fillcolor=\"#000000\" >";
ifs+="<v:stroke on=\"0\" />";
ifs+="<v:path textpathok=\"t\" />";
ifs+="<v:textpath on=\"1\" style='font-family:\"Times New Roman\"; font-size:14pt ' string=\"Calls Per Hour\" />";
ifs+="</v:shape>";
/*X-axis Title*/
ifs+="<v:shape style='position:absolute; width:4000; height:3000' path=\"M 0,2900 L 4000,2900\" fillcolor=\"#000000\" >";
ifs+="<v:stroke on=\"0\" />";
ifs+="<v:path textpathok=\"t\" />";
ifs+="<v:textpath on=\"1\" style='font-family:\"Times New Roman\"; font-size:14pt' string=\"Starting Interval\" />";
ifs+="</v:shape>";
ifs+="</v:group>";
ifs+="</div>";
ifs+="</div>";
ifs+="</body>";
ifs+="</html>";
window.onload = function wr(){ document.write(ifs);document.close;}